class EXAMPLE3
-- A small app to convert inches to centimeters and viceversa.

insert
	IUP_INTERFACE

create {ANY}
   make

feature {ANY}
	
	t1, t2: IUP_TEXT
	rd: IUP_RADIO
	
   make
      local
 			gui: IUP
			i: STRING
			op1, op2: IUP_TOGGLE
			l: IUP_LABEL
			b: IUP_BUTTON
			h1, h2: IUP_HBOX
			v: IUP_VBOX
			w: IUP_DIALOG

      do
			gui := iup_open

			-- Create two toggle buttons and associate names with these.
			create op1.toggle("in to cm") 
      	op1.set_widget_name("in/cm") 
	      create op2.toggle("cm to in")
	      op2.set_widget_name("cm/in")

	      -- Put toggle buttons inside a radio container.		
			create h1.hbox({ARRAY[IUP_WIDGET] 1, << op1, op2 >>})
	     	create rd.radio(h1)

	      -- Create two text field, one for the user entry and other for the 
      	-- result.	
	      create t1.text
	      t1.set_mask("IUP_MASK_FLOAT") -- Only allow float numbers.
	      create t2.text
	      t2.set_readonly(True)
			t2.set_can_focus(False)

			-- A label
	      create l.label("=")

	      -- Put these inside an horizontal box.
	      create h2.hbox({ARRAY[IUP_WIDGET] 1, << t1, l, t2 >>})
      	h2.set_gap(10)

			-- Create a button and connect the callback.
	      create b.button("Convert")
			b.set_cb_action(agent convert_units(?))
			b.set_maxsize(70, 30)
			b.set_expand("YES")

			-- Put all the widgets inside a vertical box.
	      create v.vbox({ARRAY[IUP_WIDGET] 1, << rd, h2, b >>})
	      v.set_alignment("ACENTER")
			v.set_gap(10)
			v.set_margin(10, 10)

			-- Create the window.
	      create w.dialog(v)
			w.set_title("Convert units")
	      i := w.show

         gui.main_loop
			gui.close
      end

	convert_units (widget: IUP_WIDGET): STRING
		local
			str, tgl: STRING
			rst: REAL
		do
			str := t1.get_value
			tgl := rd.get_value

			if tgl.is_equal("in/cm") then
				rst := 2.54*str.to_real
			else
				rst := 0.393701*str.to_real
			end
			
			t2.set_value(rst.to_string)

			Result := "IUP_DEFAULT"
		end

end -- class EXAMPLE3
